import pysnowball as ball
from pysnowball.utls import fetch_without_token, fetch
from pysnowball.api_ref import *

import requests
import os, sys, time, datetime
import json
r = requests.get("https://xueqiu.com/hq/detail?market=CN&first_name=0&second_name=0&type=sh_sz", headers={"user-agent":"Mozilla"})
print(r.cookies["xq_a_token"], r.cookies["u"])

ball.set_token(f'xq_a_token={r.cookies["xq_a_token"]}; u={r.cookies["u"]}')
# s = ball.cash_flow('SH600000')
# s = ball.quotec('SZ002027')

s = fetch(realtime_list)
stocks = [r['symbol'] for r in s['data']['list']]
# print(stocks)

# s = fetch(realtime_kline % (stocks[0], "15m", datetime.datetime(2025, 1, 1).timestamp()))
url = realtime_kline % ("SZ002027", "day", datetime.datetime(2025, 1, 1).timestamp())
# s = fetch("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=SZ002027&period=15m&begin=1735660800")
s = fetch(url)
print(url, [datetime.datetime.fromtimestamp(r[0]/1000) for r in s['data']['item']])

# r = requests.get(url, headers={"user-agent":"Mozilla"})
# print(url, r.content.decode())